<template>
    <div>
        <button @click="startScan">开始扫描</button>
        <BarcodeScanner
            v-if="scanning"
            @scan-success="handleScanSuccess"
            @scan-error="handleScanError"
        />
        <div v-if="result">扫描结果：{{ result }}</div>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import BarcodeScanner from './scan/ScanBar.vue';

const scanning = ref(false);
const result = ref('');

const startScan = () => {
    scanning.value = true;
};

const handleScanSuccess = (isbn: string) => {
    result.value = isbn;
    scanning.value = false;
};

const handleScanError = (error: Error) => {
    console.error('扫描失败:', error);
    scanning.value = false;
};
</script>
